﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Threading;
using System.Drawing.Printing;
using System.Security.Cryptography;
using PatentApp.Data;
using NHibernate.Mapping;
using PatentApp.Models;
using NHibernate.Criterion;

namespace PatentApp
{
    public partial class dlgMain : Form
    {
        private Access loggedUser;

        public Produkt addProduct { get; set; }
        public Produkt updateProduct { get; set; }
        public dlgUpdatePayment updateDialog { get; set; }

        public dlgMain()
        {
            InitializeComponent();
            foreach (Control control in this.Controls)
                control.Visible = true;
            foreach (TabPage tab in TabContainer.TabPages)
                TabContainerHidden.TabPages.Add(tab);
            TabContainer.TabPages.Clear();
            TabContainerHidden.Visible = false;
            fillDataDICToolStrip.Visible = false;
            fillDataSapToolStrip.Visible = false;
            TabHideOpen("PanelAdministracyjny");
            TabInit("PanelAdministracyjny");
            updateDialog = new dlgUpdatePayment();
            DialogResult res = updateDialog.ShowDialog();
            if (res == DialogResult.Yes) {
                if (updateDialog.produkts.Count > 0 && updateDialog.produkts[updateDialog.Index] != null)
                {
                    updateProduct = updateDialog.produkts[updateDialog.Index];
                    TabHideOpen("Aktualizujzgloszenie");
                    TabInit("Aktualizujzgloszenie");
                }
            }
        }

        public dlgMain(Access loggedUser)
        {
            InitializeComponent();
            this.loggedUser = loggedUser;
            foreach (Control control in this.Controls)
                control.Visible = true;
            foreach (TabPage tab in TabContainer.TabPages)
                TabContainerHidden.TabPages.Add(tab);
            TabContainer.TabPages.Clear();
            TabContainerHidden.Visible = false;
            fillDataDICToolStrip.Visible = false;
            fillDataSapToolStrip.Visible = false;
            TabHideOpen("PanelAdministracyjny");
            TabInit("PanelAdministracyjny");
            updateDialog = new dlgUpdatePayment();
            DialogResult res = updateDialog.ShowDialog();
            if (res == DialogResult.Yes)
            {
                if (updateDialog.produkts.Count > 0 && updateDialog.produkts[updateDialog.Index] != null)
                {
                    updateProduct = updateDialog.produkts[updateDialog.Index];
                    TabHideOpen("Aktualizujzgloszenie");
                    TabInit("Aktualizujzgloszenie");
                }
            }
        }

        private string GetMD5HashFromFile(string path)
        {
            FileStream file = new FileStream(path, FileMode.Open);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(file);
            file.Close();

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < retVal.Length; i++)
            {
                sb.Append(retVal[i].ToString("x2"));
            }
            return sb.ToString();
        }

        private void TabInit(string p)
        {
            switch (p)
            {
                case "PanelAdministracyjny":
                    lblDateNow.Text = "Dziś jest " + DateTime.Now.ToString("dddd \r\n")
                        + DateTime.Now.ToString(" dd MMMM yyyy \r\n") +
                        "Godzina " + DateTime.Now.ToString("HH:mm:ss"); 
                    using (var session = NHibernateCfg.OpenSession())
                        dgvZgloszenia.DataSource = (from prods in session.QueryOver<Produkt>() orderby prods.DataOgloPat select prods).Asc.List<Produkt>();
                    break;
                case "Wyszukiwanie":
                    ddlFindCategory.SelectedIndex = 1;
                    txtFindValue.Text = "";
                    dgvFind.DataSource = null;
                    break;
                case "Dodajzgloszenie":
                    IList<Produkt> listTmp; 
                    using (var session = NHibernateCfg.OpenSession())
                    {
                        listTmp = session.CreateCriteria<Produkt>().List<Produkt>();
                        ddlAddKategoria.DataSource = session.CreateCriteria<Kategoria>().List<Kategoria>().ToArray<Kategoria>();
                        ddlAddSlowaKluczowe.DataSource = session.CreateCriteria<SlowoKluczowe>().List<SlowoKluczowe>().ToArray<SlowoKluczowe>();
                        dgvPracownicy.DataSource = (from users in session.QueryOver<Pracownik>() orderby users.PracownikId select users).Asc.List<Pracownik>();  
                    }
                    txtAddNumRoczny.Text = (listTmp.Count == 0) ? "1" : (listTmp.Max<Produkt>(x=>x.NrRoczny)+1).ToString();
                    txtAddOgolny.Text = (listTmp.Count == 0) ? "1" : (listTmp.Max<Produkt>(x => x.NrOgolny) + 1).ToString();
                    ClearAddZgloTabForm();
                    break;
                case "Dodajpracownika":
                    ClearAddPracTabForm();
                    break;
                case "Aktualizujzgloszenie":
                    ClearUpdateZgloTabForm();
                    if (updateProduct == null)
                        return;
                    using (var session = NHibernateCfg.OpenSession())
                    {
                        updateProduct = (from prods in session.QueryOver<Produkt>() where prods.ProduktId == updateProduct.ProduktId select prods).SingleOrDefault<Produkt>();
                        dgvUpdatePrac.DataSource = updateProduct.Pracownicy;
                        txtUpdateCategorie.Text = updateProduct.Kategoria.Nazwa;
                    }
                    txtUpdateNumOgol.Text = updateProduct.NrOgolny.ToString();
                    txtUpdateNumRocz.Text = updateProduct.NrRoczny.ToString();
                    txtUpdateZglNum.Text = (updateProduct.NrZgloszenia == null) ? "" : updateProduct.NrZgloszenia.ToString();
                    txtUpdatePatentNum.Text = (updateProduct.NrPatentu == null)?"":updateProduct.NrPatentu.ToString();
                    txtUpdateTitle.Text = updateProduct.Tytul;
                    txtUpdateKeyWord.Text = updateProduct.SlowoKluczowe;
                    txtUpdateOwner.Text = updateProduct.WlascicielPraw;
                    txtUpdateDate.Text = updateProduct.DataZglTworcy.ToShortDateString();
                    chkUpdatePlatnosc.Checked = updateProduct.Platnosc;
                    if (updateProduct.DataZgloszenia.HasValue)
                        dtUpdateZglDate.Text = updateProduct.DataZgloszenia.Value.ToShortDateString();
                    if (updateProduct.DataOgloZglo.HasValue){
                        chkDate1.Checked = true;
                        dtUpdateOglDate.Enabled = true;
                        dtUpdateOglDate.Text = updateProduct.DataOgloZglo.Value.ToShortDateString();
                    }
                    else
                    {
                        chkDate1.Checked = false;
                        dtUpdateOglDate.Enabled = false;
                    }
                    if (updateProduct.DataOgloPat.HasValue){
                        chkDate2.Checked = true;
                        dtUpdateOglDate2.Enabled = true;
                        dtUpdateOglDate2.Text = updateProduct.DataOgloPat.Value.ToShortDateString();
                    }
                    else
                    {
                        chkDate2.Checked = false;
                        dtUpdateOglDate2.Enabled = false;
                    }
                    break;
                default:
                    break;
            }
           
        }
                       
        private void TabHideOpen(String name)
        {
            if (name == "Aktualizujzgloszenie" && TabContainer.TabPages[name] != null)
                updateProduct = null;
            if (TabContainer.TabPages[name] != null)
            {
                TabContainerHidden.TabPages.Add(TabContainer.TabPages[name]);
                TabContainer.TabPages.Remove(TabContainerHidden.TabPages[name]);
            }
            else
            {
                TabContainer.TabPages.Add(TabContainerHidden.TabPages[name]);
                TabContainerHidden.TabPages.Remove(TabContainer.TabPages[name]);
                try
                {
                    TabContainer.SelectTab(name);
                }
                catch(Exception e){}
            }
        }

        private void oProgramieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabHideOpen("About");
        }

        private void pnlAdminToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabHideOpen("PanelAdministracyjny");
            TabInit("PanelAdministracyjny");
        }

        private void dodajZgloszenieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabHideOpen("Dodajzgloszenie");
            TabInit("Dodajzgloszenie");
        }

        private void aktualizujZgłoszenieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgvZgloszenia.SelectedRows.Count == 0 || (TabContainer.SelectedTab != null && TabContainer.SelectedTab.Name != "PanelAdministracyjny"))
            {
                dlgSearch dlg = new dlgSearch();
                if (dlg.ShowDialog() == DialogResult.OK && dlg.result!= null)
                {
                    updateProduct = dlg.result;
                    TabHideOpen("Aktualizujzgloszenie");
                    TabInit("Aktualizujzgloszenie");
                }
                else
                {
                    MessageBox.Show("Nie zwrócono wyników wyszukiwania");
                }
            }
            else
            {
                updateProduct = (Produkt)dgvZgloszenia.SelectedRows[0].DataBoundItem;        
                TabHideOpen("Aktualizujzgloszenie");
                TabInit("Aktualizujzgloszenie");            
            }
        }

        private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Abort;
        }

        private void wylogujToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void updatePlatnosciToolStripMenuItem_Click(object sender, EventArgs e)
        {
            updateDialog = new dlgUpdatePayment();
            DialogResult res = updateDialog.ShowDialog();
            if (res == DialogResult.Yes)
            {
                if (updateDialog.produkts.Count > 0 && updateDialog.produkts[updateDialog.Index]!= null) {
                    updateProduct = updateDialog.produkts[updateDialog.Index];
                    TabHideOpen("Aktualizujzgloszenie");
                    TabInit("Aktualizujzgloszenie");
                }
            }
        }
        
        #region MainTab
        private void dgvZgloszenia_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvZgloszenia.SelectedRows.Count > 0)
                updateProduct = (Produkt)dgvZgloszenia.SelectedRows[0].DataBoundItem;
        }
        #endregion
        
        #region AddZgloTab
        private void btnAddCancel_Click(object sender, EventArgs e)
        {
            TabHideOpen("Dodajzgloszenie");
            TabInit("Dodajzgloszenie");
        }

        private void btnAddPracownik_Click(object sender, EventArgs e)
        {
            TabHideOpen("Dodajpracownika");
            TabInit("Dodajpracownika");
        }

        private void btnAddSlowoKluczow_Click(object sender, EventArgs e)
        {
            if (new dlgKeyWords().ShowDialog() == DialogResult.OK)
                using (var session = NHibernateCfg.OpenSession())
                    ddlAddSlowaKluczowe.DataSource = session.CreateCriteria<SlowoKluczowe>().List<SlowoKluczowe>().ToArray<SlowoKluczowe>();
        }

        private void btnAddNext_Click(object sender, EventArgs e)
        {
            if (txtAddNumRoczny.Text.Length == 0 || txtAddOgolny.Text.Length == 0 || txtAddTytul.Text.Length == 0 || txtAddOwner.Text.Length == 0 ||  
                ddlAddKategoria.Items.Count==0 || ddlAddKategoria.SelectedValue.ToString().Length == 0 ||
                ddlAddSlowaKluczowe.Items.Count==0 || ddlAddSlowaKluczowe.SelectedValue.ToString().Length == 0)
                return;
            pnlStep1.Visible = false;
            pnlStep2.Visible = true;
            using (var session = NHibernateCfg.OpenSession())
                addProduct = new Produkt
                {
                    NrOgolny = int.Parse(txtAddOgolny.Text),
                    NrRoczny = int.Parse(txtAddNumRoczny.Text),
                    Kategoria = session.Get<Kategoria>(int.Parse(ddlAddKategoria.SelectedValue.ToString())),
                    Tytul = txtAddTytul.Text,
                    SlowoKluczowe = ddlAddSlowaKluczowe.SelectedValue.ToString(),
                    WlascicielPraw = txtAddOwner.Text,
                    DataZglTworcy = dpAddDataZglo.Value
                };
        }

        private void btnAddEnd_Click(object sender, EventArgs e)
        {
            pnlStep1.Visible = true;
            pnlStep2.Visible = false;
            using (var session = NHibernateCfg.OpenSession()){
                using (var transaction = session.BeginTransaction())
                {
                    session.Save(addProduct);
                    transaction.Commit();
                }
            }
            TabInit("PanelAdministracyjny");
            TabHideOpen("Dodajzgloszenie");
            Directory.CreateDirectory(Application.StartupPath + "\\Katalogi\\" + addProduct.NrOgolny.ToString());
            addProduct = null;
        }

        private void btnPrzypiszTworce_Click(object sender, EventArgs e)
        {
            if(dgvPracownicy.SelectedRows.Count>0){
                Pracownik pracTemp = (Pracownik)dgvPracownicy.SelectedRows[0].DataBoundItem;
                if (addProduct.Pracownicy.Contains(pracTemp))
                    MessageBox.Show("Pracownik już jest przypisany");
                else
                    addProduct.Pracownicy.Add(pracTemp);
            }            
        }

        private void ClearAddZgloTabForm()
        {
            txtAddPracName.Text = txtAddPracNazwisko.Text = txtAddPracUnit.Text = "";
            ddlAddPracTitle.SelectedIndex = 0;
        }
        #endregion

        #region AddPracTab
        private void btnAddPracAdd_Click(object sender, EventArgs e)
        {
            if (txtAddPracName.Text.Length == 0 || txtAddPracNazwisko.Text.Length == 0 || txtAddPracUnit.Text.Length == 0)
                return;
            using (var session = NHibernateCfg.OpenSession())
            {
                var prac = new Pracownik
                {
                    Imie = txtAddPracName.Text,
                    Nazwisko = txtAddPracNazwisko.Text,
                    Wydzial = txtAddPracUnit.Text,
                    Tytul = ddlAddPracTitle.SelectedItem.ToString()
                };
                session.SaveOrUpdate(prac);
            }
            TabHideOpen("Dodajpracownika");
            using (var session = NHibernateCfg.OpenSession())
                dgvPracownicy.DataSource = (from users in session.QueryOver<Pracownik>() orderby users.PracownikId select users).Asc.List<Pracownik>();  
        }

        private void btnAddPracBack_Click(object sender, EventArgs e)
        {
            TabHideOpen("Dodajpracownika");
        }

        private void ClearAddPracTabForm()
        {
            txtAddPracName.Text = txtAddPracNazwisko.Text = txtAddPracUnit.Text = "";
            ddlAddPracTitle.SelectedIndex = 0;
        }
        #endregion

        #region UpdateZgloTab
        private void btnUpdateBack_Click(object sender, EventArgs e)
        {
            TabHideOpen("Aktualizujzgloszenie");
        }

        private void btnUpdateAccept_Click(object sender, EventArgs e)
        {
            using (var session = NHibernateCfg.OpenSession()){
                Produkt pr = (from prod in session.QueryOver<Produkt>() where prod.ProduktId == updateProduct.ProduktId select prod).SingleOrDefault<Produkt>();
                pr.NrZgloszenia = txtUpdateZglNum.Text;
                pr.NrPatentu = txtUpdatePatentNum.Text;
                pr.Tytul = txtUpdateTitle.Text;
                pr.Platnosc = chkUpdatePlatnosc.Checked;
                pr.SlowoKluczowe = txtUpdateKeyWord.Text;
                pr.WlascicielPraw = txtUpdateOwner.Text;
                if (txtUpdateDate.Text.Length > 0)
                    pr.DataZglTworcy = DateTime.Parse(txtUpdateDate.Text);
                if (dtUpdateZglDate.Text.Length > 0)
                    pr.DataZgloszenia = DateTime.Parse(dtUpdateZglDate.Text);
                if (dtUpdateOglDate.Enabled)
                    pr.DataOgloZglo = DateTime.Parse(dtUpdateOglDate.Text);
                if (dtUpdateOglDate2.Enabled)
                    pr.DataOgloPat = DateTime.Parse(dtUpdateOglDate2.Text);
                session.Update(pr);
                session.Flush();
            }
            updateProduct = null;
            using (var session = NHibernateCfg.OpenSession())
                dgvZgloszenia.DataSource = (from prods in session.QueryOver<Produkt>() orderby prods.DataOgloPat select prods).Asc.List<Produkt>();
            TabHideOpen("Aktualizujzgloszenie");
        }

        private void ClearUpdateZgloTabForm()
        {
            dgvUpdatePrac.DataSource = null;
            txtUpdateCategorie.Text = txtUpdateNumOgol.Text = txtUpdateNumRocz.Text = txtUpdateZglNum.Text = txtUpdatePatentNum.Text =
                                                                                       txtUpdateTitle.Text =
                                                                                       txtUpdateKeyWord.Text =
                                                                                       txtUpdateOwner.Text =
                                                                                       txtUpdateDate.Text =
                                                                                       dtUpdateZglDate.Text =
                                                                                       dtUpdateZglDate.Text =
                                                                                       dtUpdateOglDate.Text =
                                                                                       dtUpdateOglDate2.Text = "";
        }
        #endregion

        private void wyszukajToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabHideOpen("Wyszukiwanie");
            TabInit("Wyszukiwanie");
        }

        private void pismaToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void katalogiToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void raportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new dlgRaport(this.loggedUser).ShowDialog();
        }

        private void dodajPracownikaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabHideOpen("Dodajpracownika");
            TabInit("Dodajpracownika");
        }

        private void updatePlatnosciToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            updateDialog = new dlgUpdatePayment();
            DialogResult res = updateDialog.ShowDialog();
            if (res == DialogResult.Yes)
            {
                updateProduct = updateDialog.produkts[updateDialog.Index];
                TabHideOpen("Aktualizujzgloszenie");
                TabInit("Aktualizujzgloszenie");
            }
        }

        private void btnUpdateAddPlat_Click(object sender, EventArgs e)
        {
            chkUpdatePlatnosc.Checked = !chkUpdatePlatnosc.Checked;
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            if(txtFindValue.Text.Length==0  && dgvFindValue.Text.Length==0)
                return;
            switch (ddlFindCategory.SelectedItem.ToString() )
            {
                case "Tytuł":
                    using (var session = NHibernateCfg.OpenSession())
                        dgvFind.DataSource = (from prods in session.QueryOver<Produkt>() where prods.Tytul.IsLike("%" + txtFindValue.Text + "%") orderby prods.DataOgloPat select prods).Asc.List<Produkt>();
                    break;
                case "Twórca":
                    using (var session = NHibernateCfg.OpenSession()){
                        List<Pracownik> pracList = (from prac in session.QueryOver<Pracownik>() where (prac.Imie.IsLike("%" + txtFindValue.Text + "%") || prac.Nazwisko.IsLike("%" + txtFindValue.Text + "%") || prac.Tytul.IsLike("%" + txtFindValue.Text + "%")) select prac).List<Pracownik>().ToList<Pracownik>();
                        List<Produkt> prodlist = new List<Produkt>();
                        if(pracList.Count>0)
                            foreach (Pracownik item in pracList)
                               prodlist.AddRange(item.Produkty);
                        dgvFind.DataSource = prodlist;                            
                    }
                    break;
                case "Kategoria":
                    using (var session = NHibernateCfg.OpenSession()){
                        Kategoria cat = (from prac in session.QueryOver<Kategoria>() where prac.Nazwa.IsLike("%" + txtFindValue.Text + "%") select prac).SingleOrDefault();
                        dgvFind.DataSource = (from prods in session.QueryOver<Produkt>() where prods.Kategoria.KategoriaId == cat.KategoriaId orderby prods.DataOgloPat select prods).Asc.List<Produkt>();
                    }break;
                case "Data Zgłoszenia":
                    using (var session = NHibernateCfg.OpenSession())
                        dgvFind.DataSource = ((from prods in session.QueryOver<Produkt>() orderby prods.DataZglTworcy select prods).Asc.List<Produkt>().ToList<Produkt>().FindAll(x => x.DataZgloszenia.HasValue && x.DataZgloszenia.Value.ToShortDateString() == dgvFindValue.Value.ToShortDateString()));
                    break;
                case "Data Ogłoszenia o Zgłoszeniu":
                    using (var session = NHibernateCfg.OpenSession())
                        dgvFind.DataSource = ((from prods in session.QueryOver<Produkt>() orderby prods.DataZglTworcy select prods).Asc.List<Produkt>().ToList<Produkt>().FindAll(x => x.DataZglTworcy.ToShortDateString()== dgvFindValue.Value.ToShortDateString()));
                    break;
                case "Data Zatwierdzenia Patentu":
                    using (var session = NHibernateCfg.OpenSession())
                        dgvFind.DataSource = ((from prods in session.QueryOver<Produkt>() orderby prods.DataZglTworcy select prods).Asc.List<Produkt>().ToList<Produkt>().FindAll(x => x.DataOgloPat.HasValue && x.DataOgloPat.Value.ToString() == dgvFindValue.Value.ToShortDateString()));
                    break;
                case "Właściciel Praw":
                    using (var session = NHibernateCfg.OpenSession())
                        dgvFind.DataSource = (from prods in session.QueryOver<Produkt>() where prods.WlascicielPraw.IsLike("%" + txtFindValue.Text + "%") orderby prods.DataOgloPat select prods).Asc.List<Produkt>();
                    break;
                case "Słowo Kluczowe":
                    using (var session = NHibernateCfg.OpenSession())
                        dgvFind.DataSource = (from prods in session.QueryOver<Produkt>() where prods.SlowoKluczowe.IsLike("%" + txtFindValue.Text + "%") orderby prods.DataOgloPat select prods).Asc.List<Produkt>();
                    break;       
                    //innne case
                default:
                    break;
            }
        }

        private void btnFindBack_Click(object sender, EventArgs e)
        {
            TabHideOpen("Wyszukiwanie");
        }

        private void btnFindDetail_Click(object sender, EventArgs e)
        {
            if (dgvFind.SelectedRows.Count > 0)
            {
                Produkt prd = (Produkt) dgvFind.SelectedRows[0].DataBoundItem;
                dlgDetails dlg = new dlgDetails(prd);
                DialogResult res = dlg.ShowDialog();
                if (res == DialogResult.Retry)
                {
                    updateProduct = prd;
                    TabHideOpen("Aktualizujzgloszenie");
                    TabInit("Aktualizujzgloszenie");
                }
            }
        }

        private void dodajSłowoKluczoweToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (new dlgKeyWords().ShowDialog() == DialogResult.OK)
                using (var session = NHibernateCfg.OpenSession())
                    ddlAddSlowaKluczowe.DataSource = session.CreateCriteria<SlowoKluczowe>().List<SlowoKluczowe>().ToArray<SlowoKluczowe>();
        }

        private void btnUpdateSendOgl_Click(object sender, EventArgs e)
        {
            new dlgDocs(Application.StartupPath+"\\Documents\\Zgloszenie").ShowDialog();
        }

        private void btnUpdateSendUPRP_Click(object sender, EventArgs e)
        {
            new dlgDocs(Application.StartupPath + "\\Documents\\Zgloszenie").ShowDialog();
        }

        private void dodajKategorieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (new dlgCategory().ShowDialog() == DialogResult.OK)
                using (var session = NHibernateCfg.OpenSession())
                    ddlAddKategoria.DataSource = session.CreateCriteria<Kategoria>().List<Kategoria>().ToArray<Kategoria>();
        }

        private void btnAddCategory_Click(object sender, EventArgs e)
        {
            if (new dlgCategory().ShowDialog() == DialogResult.OK)
                using (var session = NHibernateCfg.OpenSession())
                    ddlAddKategoria.DataSource = session.CreateCriteria<Kategoria>().List<Kategoria>().ToArray<Kategoria>();
        }

        private void btnAboutOk_Click(object sender, EventArgs e)
        {
            TabHideOpen("About");
        }

        private void pismaToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(Application.StartupPath + "\\Documents\\");
        }

        private void katalogiToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(Application.StartupPath + "\\Katalogi\\");
        }

        private void ddlFindCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (ddlFindCategory.SelectedItem.ToString())
            {
                case "Data Zgłoszenia":
                case "Data Ogłoszenia o Zgłoszeniu":
                case "Data Zatwierdzenia Patentu":
                    txtFindValue.Visible = false;
                    dgvFindValue.Visible = true;
                    txtFindValue.Text = "";
                    dgvFindValue.Text = "";
                    break;
                default:
                    txtFindValue.Visible = true;
                    dgvFindValue.Visible = false;
                    txtFindValue.Text = "";
                    dgvFindValue.Text = "";
                    break;
            }
        }

        private void chkDate1_CheckedChanged(object sender, EventArgs e)
        {
            dtUpdateOglDate.Enabled = !dtUpdateOglDate.Enabled;
        }

        private void chkDate2_CheckedChanged(object sender, EventArgs e)
        {
            dtUpdateOglDate2.Enabled = !dtUpdateOglDate2.Enabled;
        }
    }
}